define(function (require, exports, module) {

  require("mixins/global.mixins.js");
  var mCard = require('andrew/card/index.js')
  var toastr = require("third/toastr/index.js");

  var api = require('service/api.js');
  let id = 1000;
  var pageVue = new Vue({
    data: {
      CategoryTreeList: [],
      filterText: '',
      formCollapse: false
    },
    watch: {
      filterText(val) {
        this.$refs.tree2.filter(val);
      }
    },
    mounted: function () {
      this.queryCategoryTreeList();
    },
    methods: {
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      queryCategoryTreeList: function () {
        var curPageVue = this;
        var data = {};
        $.ajax({
          type: 'POST',
          url: QUERY_CONFIG_GROUP_LIST_URL,
          contentType: 'application/json',
          data: JSON.stringify(data),
          dataType: "json",
          success: function (result) {
            console.log(result);
            curPageVue.CategoryTreeList = [];
            curPageVue.CategoryTreeList = result;
          }
        });
      },
      append: function (row) {
        pageVue = this
        var url = "";
        if(row == undefined){
          url = 'edit.html?parentId=0';
        }else if(row.level == 1){
          url = 'edittemp.html?parentId=' + row.id + "&position=" + row.position;
        }else if(row.level == 2){
          url = 'edititem.html?parentId=' + row.id + "&position=" + row.position + "&templet=" + row.templet;
        }
        layer.open({
          type: 2,
          title: '文章基本信息修改',
          shade: [0],
          area: ['50%', '50%'],
          end: function(){
            pageVue.queryCategoryTreeList();
          },
          content: [url] // iframe的url，no代表不显示滚动条
        });
      },

      remove: function (data) {
        pageVue = this;
        layer.confirm('分类信息可能已经被绑定，是否删除？', {
          btn: ['确认', '取消'] //按钮
        }, function (index) {
          layer.close(index);
          
          $.ajax({
            url: REMOVE_CONFIG_GROUP + data.id,//这里是后台接口需要换掉
            type: 'POST',
            contentType: 'application/json',
            dataType: "json",
            cache: false,
            processData: false,
            success: (res) => {
              if(res.errno == 0){
                pageVue.queryCategoryTreeList();
                toastr.success("分类信息删除成功!");
              }else{
                toastr.error("分类信息删除失败!");
              }
            },
            error: function (err) {
              toastr.error("网络错误");
            }
          });
        });
      },
      edit: function (row){
        pageVue = this
        var url;
        if(row.level == 1){
          url = 'edit.html?edit=true&id=' + row.id + "&position=" + row.position;
        }else if(row.level == 2){
          url = 'edittemp.html?edit=true&id=' + row.id + "&position=" + row.position;
        }else if(row.level == 3){
          url = 'edititem.html?edit=true&id=' + row.id + "&position=" + row.position + "&templet=" + row.templet;
        }
        layer.open({
          type: 2,
          title: '文章基本信息修改',
          shade: [0],
          area: ['50%', '50%'],
          content: [url] // iframe的url，no代表不显示滚动条
        });
      },
      isShow: function(level){
        alert(level);
        if(level == 3){
          return false;
        }else {
          return true;
        }
      }

    }

  }).$mount('#app')
})
